﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
using YasharEl.Infrastructure.ObjectFactory;
using YasharEl.Infrastructure.ExceptionHandling;

namespace YasharEl.Infrastructure.ResourcesManagement.ExceptionHandling
{
    public class ResourcesManagementBasedMessageTranslator : IMessageTranslator
    {
        #region ReadOnly Fields

        private readonly IDependencyResolver resolver;

        #endregion

        #region Constructors

        public ResourcesManagementBasedMessageTranslator(IDependencyResolver resolver)
        {
            Contract.Requires<ArgumentNullException>(resolver != null, "resolver could not be null.");

            this.resolver = resolver;
        }

        #endregion

        #region IMessageTranslator Methods

        public string Translate(string resourceKey)
        {
            // Each time resource manager requested it built by factory method
            // using current culture
            return resolver.Resolve<IResourceManager>().GetString(resourceKey);
        }

        #endregion
    }
}
